package com.ck.shardinggo.sysconfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * @Author yd
 * @Date 2018/10/24 13:50
 */
@Configuration
public class DateConvertorConfig {

    @Bean
    public Converter<String, Date> addNewConvertor(){
        return new Converter<String, Date>() {

            @Override
            public Date convert(String s) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date date = null;
                try{
                    date = sdf.parse((String) s);
                }catch (ParseException e){
                    e.printStackTrace();
                }
                return date;
            }
        };
    }

}
